package com.app.controller 
{
	import com.app.model.data.LevelData;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.interfaces.INotification;
	
	import com.app.AppFacade;
	
	import com.app.view.AppMediator;
	import com.app.view.manager.SceneManagerMediator;
	import com.app.view.manager.DialogManagerMediator;
	import com.app.view.component.RoomMediator;
	
	import com.app.view.component.scene.RoomScene;
	
	import com.app.model.web.Js;
	
	import com.app.model.HallConnProxy;
	import com.app.model.RoomConnProxy;
	import com.app.model.GameConfigProxy;
	import com.app.model.xml.AnalysisXMLProxy;
	import com.app.model.room.PlayerListProxy;
	import com.app.model.data.HallListItemData;
	import com.app.model.RoomListProxy;
	
	import com.app.model.data.UserData;

	import com.peachcastle.debug.Log;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class RoomCommand extends SimpleCommand implements ICommand
	{
		override public function execute(notification:INotification):void
		{
			var name:String = notification.getName();
			var params:* = notification.getBody();
			switch(name)
			{
				case RoomMediator.INIT_ROOM_REQUEST:
					requestInitRoom(int(params[0]), int(params[1]), params[2]);
				
					break;
					
				case AppMediator.ROOM_LOAD_OK:
					connRoom();
				
					break;
				
				case AppFacade.READY_ENTER_ROOM:
					readyEnterRoom();
				
					break;	
					
				case AppFacade.ENTER_ROOM:
					enterRoom(params[0]);
				
					break;
					
				case RoomMediator.SIT_DOWN_REQUEST:
					requestSitDown(params[0]);
				
					break;
					
				case RoomMediator.REAL_SIT_DOWN_REQUEST:
					requestRealSitDown(params[0]);
				
					break;
					
				case AppFacade.SIT_DOWN:
					responseSitDown(params[0]);
				
					break;
					
				case RoomMediator.STAND_REQUEST:
					requestStand();
				
					break;
					
				case AppFacade.STAND:
					stand(params[0]);
				
					break;
					
				case RoomMediator.GO_HALL_REQUEST:
					requestGoHall();
				
					break;
					
				case AppFacade.GO_HALL:
					goHall(params[0]);
				
					break;
				
				case RoomMediator.START_GAME_REQUEST:
					startGameRequest();
				
					break;
					
				case AppFacade.START_GAME:
					startGame(params[0]);
				
					break;
					
				case RoomMediator.BASE_POUR_REQUEST:
					basePourRequest(params[0], params[1]);
				
					break;
					
				case AppFacade.ADD_BASE_POUR:
					addBasePour(params[0]);
				
					break;
					
				case AppFacade.CALL_POUR_START:
					startCallPour(params[0]);
				
					break;
					
				case RoomMediator.POUR_REQUEST:
					pourRequest(params[0], params[1], params[2]);
				
					break;
					
				case AppFacade.CALL_POUR:
					callPour(params[0]);
				
					break;
					
				case AppFacade.START_PK:
					startPk(params[0]);
				
					break;
					
				case RoomMediator.PK_RESULT_REQUEST:
					pkResultRequest(params[0], params[1], params[2]);
				
					break;
					
				case AppFacade.PK_RESULT:
					pkResult(params[0]);
				
					break;
					
				case AppFacade.GAME_OVER:
					gameOver();
				
					break;
					
				case AppFacade.HEARTBAET_USER_CLOSE:
					shotUser(); //通知用户
				
					break;
					
				case RoomMediator.CHAT_REQUEST:
					roomConnP.sendData('chat', { msg: gameConfigP.self.name + ": " + params[0] });
				
					break;
						
				case AppFacade.CHAT:
					sendNotification(RoomMediator.CHAT_RESPONSE, [params[0].sms]);
				
					break;
					
				case RoomMediator.EXPRESSION_REQUEST:
					roomConnP.sendData('expression', {tomid: 0, flag: params[0]});
				
					break;
					
				case AppFacade.EXPRESSION:
					expressionDeal(params[0]);

					break;
					
				case RoomMediator.SHOW_LAST_RESULT_REQUEST:
					showLastResult();
					
					break;
					
				default:
				
					break;
			}
			
		}
		
		private function requestInitRoom(serverid:int, roomid:int, isFastSit:Boolean = false):void
		{
			gameConfigP.roomIp = analysisXmlP.servers[serverid].host;
			gameConfigP.roomPort = analysisXmlP.servers[serverid].port;
				
			gameConfigP.roomid = roomid;
			gameConfigP.isFastSit = isFastSit;
	
			sendNotification(SceneManagerMediator.JOIN_SCENE, ["RoomScene", gameConfigP.getSwfUrl]);
		}
		
		private function connRoom():void
		{
			sendNotification(AppMediator.ROOM_CONNECT_PROGRESS, [RoomScene.NAME]);
			
			//@TODO 连接房间服务器
			roomConnP.connect(gameConfigP.roomIp, gameConfigP.roomPort, gameConfigP.self.mid, gameConfigP.roomid);
		}
		
		private function readyEnterRoom():void
		{
			roomConnP.sendData('enter_room', { } );
			
			hallConnP.close();
		}
		
		private function enterRoom(data:Object):void
		{
			sendNotification(AppMediator.ROOM_CONNECT_OK);
			
			var room:HallListItemData = roomListP.get(gameConfigP.roomid);
			if (!room)
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_12"]);
				return;
			}

			var is_banker:int = data.is_banker;
			gameConfigP.gameStatus = data.runtime_status;
			delete data.is_banker;
			delete data.runtime_status;
			
			if (!is_banker && gameConfigP.self.chips > 15000)
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_21", requestGoHall]);
				return;
			}
			
			sendNotification(RoomMediator.ADD_IN_LAYER, [gameConfigP.self, 
											gameConfigP.getCurrentLevelExp(gameConfigP.self.exp, analysisXmlP.levels), 
											room.roomid, room.name, room.minPour]); 
			
			var d:UserData = null;
			var self:UserData = null;
			if (data)
			{
				for (var i:String in data)
				{
					d = playerListP.getUidByPlayer(data[i].mid);
					if (!d)
					{
						d = new UserData();
						d.seatid = int(i.substr(1, 1));
						d.mid = int(data[i].mid);
						d.name = data[i].mnickname;
						d.icon = data[i].pic;
						d.sitChips = int(data[i].sit_chips);
						d.baseCallChips = data[i].base_pour == "null" ? -1 : int(data[i].base_pour);	//没有下底注，为 -1
						d.callChips = data[i].call_pour == "null" ? -1 : int(data[i].call_pour);		//没有加注，为 -1
						d.totalCallChips = d.baseCallChips + d.callChips;
						d.paiIds = data[i].pais ? data[i].pais : '';
						d.isOver = data[i].pk_status == "null" ? false : true;
						if (d.seatid == 1 && gameConfigP.gameStatus == RoomConnProxy.STAT_WAIT_START)
						{
							d.isOver = true;
						}
						
						playerListP.addPlayer(d);
					}
					
					if (d.mid == gameConfigP.self.mid)
					{
						self = d;
					}
				}
			}
			
			if (self && self.mid == gameConfigP.self.mid)
			{
				gameConfigP.self.seatid = self.seatid;
				gameConfigP.self.sitChips = self.sitChips;
				sendNotification(RoomMediator.SIT_DOWN_RESPONSE, [true, gameConfigP.self.seatid, self, playerListP.getSeats().length, gameConfigP.gameStatus]);
				
				Log.info("enterRoom", gameConfigP.self.seatid, gameConfigP.self.sitChips, gameConfigP.self.chips);
			}
			
			d = null;
			self = null;

			if (is_banker && !data.hasOwnProperty('s1')) 
			{
				requestSitDown(GameConfigProxy.BANKER_SEATID);
			}
			
			if (gameConfigP.isFastSit)
			{
				for (var k:int = 2; k <= 8; k++)
				{
					if (!playerListP.getPlayerInSeat(k))
					{
						requestSitDown(k);
						break;
					}
				}
			}
		}
		
		private function requestSitDown(seatid:int):void
		{
			gameConfigP.requestSeatid = seatid;
			
			if (seatid != GameConfigProxy.BANKER_SEATID)
			{
				var room:HallListItemData = roomListP.get(gameConfigP.roomid);
				if (!room)
				{
					sendNotification(AppFacade.CLIENT_NOTICE, ["error_12"]);
					return;
				}
				sendNotification(DialogManagerMediator.SHOW_DIALOG, ['exchangeView', {'userChip': gameConfigP.self.chips, 'minPour': room.minPour}])
			}else
			{
				requestRealSitDown(gameConfigP.self.chips);	//庄家坐下
			}
			
			gameConfigP.isReExchangeChip = false;
		}
		
		private function requestRealSitDown(chip:int):void
		{
			roomConnP.sendData('sit_down', {"seatid": ('s' + gameConfigP.requestSeatid), "chip": chip} );
			gameConfigP.requestSeatid = 0;
			gameConfigP.self.sitChips = chip;
		}
		
		private function responseSitDown(data:Object):void
		{
			var user:UserData = new UserData();
			user.mid = data.mid,
			user.name = data.mnickname;
			user.sex = data.sex;
			user.icon =  data.pic;
			user.sitChips = data.chips;
			user.seatid = int(data.seatid.substr(1, 1));
			playerListP.addPlayer(user);
			
			Log.debug("responseSitDown", user.mid, user.seatid);
			
			var isSelf:Boolean = false;
			if (user.mid == gameConfigP.self.mid)
			{
				isSelf = true;
				gameConfigP.self.seatid = user.seatid;
				if (user.seatid != GameConfigProxy.BANKER_SEATID)
				{
					gameConfigP.self.chips = gameConfigP.self.chips - user.sitChips;
				}
				if (data.runtime_status == RoomConnProxy.STAT_WAIT_START) user.isOver = true;
				
				user.chips = gameConfigP.self.chips;
				
				Log.info("responseSitDown", user.sitChips, gameConfigP.self.sitChips, gameConfigP.self.chips);
			}

			sendNotification(RoomMediator.SIT_DOWN_RESPONSE, [isSelf, gameConfigP.self.seatid, user, playerListP.getSeats().length, gameConfigP.gameStatus]);
		}
		
		private function requestStand():void
		{
			roomConnP.sendData('sit_up', {seatid: 's' + gameConfigP.self.seatid});
		}
		
		private function stand(data:Object):void
		{
			data.seatid = int(data.seatid.substr(1, 1));
			if (data.seatid > 0)
			{
				playerListP.removePlayer(data.mid);

				var isSelf:Boolean = false;
				if (data.mid == gameConfigP.self.mid)
				{
					isSelf = true;
	
					if (gameConfigP.self.seatid > GameConfigProxy.BANKER_SEATID && gameConfigP.self.sitChips > 0)
					{
						gameConfigP.self.chips = gameConfigP.self.chips + gameConfigP.self.sitChips;
					}
					
					if (gameConfigP.isReExchangeChip)
					{
						requestSitDown(gameConfigP.self.seatid);
					}
					
					gameConfigP.self.seatid = 0;
					
					Log.info("stand", gameConfigP.self.sitChips, gameConfigP.self.chips);
				}

				sendNotification(RoomMediator.STAND_RESPONSE, 
									[isSelf, data.seatid, playerListP.getSeats(), gameConfigP.self, gameConfigP.gameStatus]);
			}
		}
		
		private function requestGoHall():void
		{
			gameConfigP.roomid = 0;
			gameConfigP.serverid = 0;
			roomConnP.sendData('go_hall', {});
		}
		
		private function goHall(data:Object):void
		{
			stand(data);
			
			Log.debug("goHall...", data.is_banker, data.mid, gameConfigP.self.mid);
			
			if (data.is_banker || data.mid == gameConfigP.self.mid)
			{
				playerListP.removeAll();
				sendNotification(AppFacade.INIT_HALL, [gameConfigP.hallIp, gameConfigP.hallPort]);
			}
		}
		
		private function startGameRequest():void
		{
			roomConnP.sendData('start_game', {});
		}
		
		private function startGame(data:Object):void
		{
			Log.debug("startGame", gameConfigP.self.seatid, gameConfigP.roomid, playerListP.getSeats());
			
			var room:HallListItemData = roomListP.get(gameConfigP.roomid);
			var seats:Array = playerListP.getSeats();
			if (room && seats)
			{
				sendNotification(RoomMediator.START_GAME_RESPONSE, [gameConfigP.self.seatid, seats, data.time, room.minPour, gameConfigP.self.sitChips]);
			}
		}
		
		private function basePourRequest(type:int, chips:int):void
		{
			if (chips >= 0)
			{
				roomConnP.sendData('add_base_pour', {type: type, chips: chips});
			}else
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_10"]);
			}
		}
		
		private function addBasePour(data:Object):void
		{
			data.seatid = int(data.seatid.substr(1, 1));
			data.chips = int(data.chips);

			var user:UserData = null;
			if (data.type == 1)
			{	//下底注成功
				user = playerListP.getUidByPlayer(data.mid);
				user.baseCallChips = data.chips;
				user.totalCallChips = data.chips;
				user.sitChips = user.sitChips - data.chips;
				if (user.mid == gameConfigP.self.mid)
				{
					gameConfigP.self.sitChips = user.sitChips;
					
					Log.info("addBasePour", data.chips, gameConfigP.self.sitChips);
				}
				sendNotification(RoomMediator.BASE_POUR_RESPONSE, [data.seatid, data.chips, user]);
			}else if (data.type == 0)
			{
				user = playerListP.getUidByPlayer(data.mid);
				user.isGiveup = true;
				sendNotification(RoomMediator.GIVE_UP_RESPONSE, [data.seatid, user.totalCallChips]);
			}
		}
		
		private function startCallPour(data:Object):void
		{
			var dice:String = data.dice;
			var clockTime:int = data.time;
			var startSeatid:int = int(data.start_seat.substr(1, 1));
			var failedUsers:Object = data.faild_users;
			
			delete data.dice;
			delete data.time;
			delete data.start_seat;
			delete data.faild_users;
			
			//获取在玩的座位数组
			var pArray1:Array = [];
			var pArray2:Array = [];
			var pais:Array = [];
			var seatid:int = 0;
			var showPourSeatid:int = 0;
			for (var i:String in data)
			{
				seatid = int(i.substr(1, 1));
				if (data[i] != null && data[i] != '' && seatid >= startSeatid)
				{
					pArray1.push(seatid);
					playerListP.getPlayerInSeat(seatid).paiIds = data[i];
					pais[seatid] = data[i];
					if (seatid == gameConfigP.self.seatid) showPourSeatid = gameConfigP.self.seatid;
				}
			}
			pArray1 = pArray1.sort(Array.NUMERIC);
			
			for (var j:String in data)
			{
				seatid = int(j.substr(1, 1));
				if (data[j] != null && data[j] != '' && seatid < startSeatid)
				{
					pArray2.push(seatid);
					playerListP.getPlayerInSeat(seatid).paiIds = data[j];
					pais[seatid] = data[j];
					if (seatid == gameConfigP.self.seatid) showPourSeatid = gameConfigP.self.seatid;
				}
			}
			pArray2 = pArray2.sort(Array.NUMERIC);
			
			sendNotification(RoomMediator.CALL_POUR_START_RESPONSE, [gameConfigP.self.seatid, clockTime, dice, startSeatid, pArray1.concat(pArray2), pais, showPourSeatid, gameConfigP.self.sitChips]);
			
			if (failedUsers)
			{
				var user:UserData = null;
				for (var k:String in failedUsers)
				{
					user = playerListP.getUidByPlayer(failedUsers[k]);
					if (user && user.seatid > GameConfigProxy.BANKER_SEATID)
						sendNotification(RoomMediator.GIVE_UP_RESPONSE, [user.seatid, user.totalCallChips]);
				}
				
				user = null;
			}
		}
		
		private function pourRequest(type:int, chips:int = 0, paiIds:String = ''):void
		{
			if (chips >= 0)
			{
				roomConnP.sendData('call_pour', {type: type, chips: chips, pais: paiIds});
			}else 
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_11"]);
			}
			
			Log.info("pourRequest", type, chips, paiIds);
		}
		
		private function callPour(data:Object):void
		{
			data.seatid = int(data.seatid.substr(1, 1));
			data.chips = int(data.chips);
			
			var user:UserData = null;
			if (data.type == 1)
			{	//加注成功
				user = playerListP.getUidByPlayer(data.mid);
				user.callChips = data.chips;
				user.totalCallChips = user.totalCallChips + data.chips;
				user.sitChips = user.sitChips - data.chips;
				if (user.mid == gameConfigP.self.mid) 
				{
					gameConfigP.self.sitChips = user.sitChips;
					
					Log.info("callPour", data.chips, gameConfigP.self.sitChips);
				}
				sendNotification(RoomMediator.POUR_RESPONSE, [data.seatid, data.chips, user.totalCallChips, user]);
			}else if (data.type == 0)
			{	//弃牌成功				
				user = playerListP.getUidByPlayer(data.mid);
				user.isGiveup = true;
				
				var banker:UserData = playerListP.getPlayerInSeat(GameConfigProxy.BANKER_SEATID);
				banker.sitChips = banker.sitChips + user.totalCallChips;
				
				if (GameConfigProxy.BANKER_SEATID == gameConfigP.self.seatid)
				{
					gameConfigP.self.chips = gameConfigP.self.chips + user.totalCallChips;
					gameConfigP.self.sitChips = gameConfigP.self.chips;
					
					gameConfigP.self.increaseExp = gameConfigP.self.increaseExp + data["b_exp"];
				}
				
				if (data.mid == gameConfigP.self.mid)
				{
					gameConfigP.self.increaseExp = data["u_exp"];
				}
				
				sendNotification(RoomMediator.GIVE_UP_RESPONSE, [data.seatid, user.totalCallChips, banker, gameConfigP.self]);
			}
		}
		
		private function startPk(data:Object):void
		{
			if (data.faild_users)
			{
				var banker:UserData = playerListP.getPlayerInSeat(1);
				
				var user:UserData = null;
				for (var k:String in data.faild_users)
				{
					user = playerListP.getUidByPlayer(data.faild_users[k]);
					if (user && user.seatid > GameConfigProxy.BANKER_SEATID)
					{
						sendNotification(RoomMediator.POUR_RESPONSE, [user.seatid, user.totalCallChips, user]);
					}
				}
				
				user = null;
			}
			
			data.start_pk_seatid = int(data.start_pk_seatid.substr(1, 1));
			if (data.start_pk_seatid > 0 && data.start_pk_seatid != GameConfigProxy.BANKER_SEATID)
			{
				var pkUser:UserData = playerListP.getPlayerInSeat(data.start_pk_seatid);
				sendNotification(RoomMediator.START_PK_RESPONSE, [gameConfigP.self.seatid, data.start_pk_seatid, data.time, pkUser.name]);
			}
		}
		
		private function pkResultRequest(seatid:int, type:int, paiIds:String):void
		{
			var user:UserData = playerListP.getPlayerInSeat(seatid);
			roomConnP.sendData('start_pk', { tomid: user.mid.toString(), type: type, pais: paiIds } );	//type 1:接受 0:认输
		}
		
		private function pkResult(data:Object):void
		{
			var banker:UserData = playerListP.getPlayerInSeat(GameConfigProxy.BANKER_SEATID);
			var playr:UserData = playerListP.getUidByPlayer(data.tomid);
			banker.sitChips = data.banker_sitchips;
			playr.sitChips = data.user_sitchips;

			playr.isOver = true;
			
			var pais:Array = [];
			pais[GameConfigProxy.BANKER_SEATID] = data.banker_pais;
			pais[playr.seatid] = data.user_pais;
			
			var pkUsername:String = '';
			if (data.hasOwnProperty('start_pk_seatid') && String(data.start_pk_seatid).length == 2)
			{
				data.start_pk_seatid = int(data.start_pk_seatid.substr(1, 1));
				
				var user:UserData = playerListP.getPlayerInSeat(data.start_pk_seatid);
				pkUsername = user.name;
			}else
			{
				data.start_pk_seatid = 0;
			}
			
			if (banker.mid == gameConfigP.self.mid)
			{
				gameConfigP.self.chips = banker.sitChips;
				gameConfigP.self.sitChips = banker.sitChips;
				
				Log.info("pkResult", data.chips, gameConfigP.self.sitChips);
				
				gameConfigP.self.increaseExp = gameConfigP.self.increaseExp + data["b_exp"];
			}else if (playr.mid == gameConfigP.self.mid) 
			{
				gameConfigP.self.sitChips = playr.sitChips;
				
				Log.info("pkResult", data.chips, gameConfigP.self.sitChips);
				
				gameConfigP.self.increaseExp = data["u_exp"];
			}
			
			var isSelf:Boolean = false;
			if (playr.mid == gameConfigP.self.mid) isSelf = true;

																// pk状态      庄家    闲家	   结果集	   赢的金币数		
			sendNotification(RoomMediator.PK_RESULT_RESPONSE, [data.pk_status, banker, playr, pais, data.chips, 
																gameConfigP.self.seatid, data.start_pk_seatid, pkUsername]);	//'pk_status': '0|1|2'	和牌/闲家赢/庄家赢	
		
			sendNotification(DialogManagerMediator.SHOW_DIALOG, ['pkResultView', {'bankerPais': pais[banker.seatid],
																					'playrPais': pais[playr.seatid],
																					'pkStatus': data.pk_status,
																					'banker': banker,
																					'playr': playr,
																					'banker_max': data.b_max,
																					'playr_max': data.u_max,
																					'isSelf': isSelf,
																					'isBanker': (gameConfigP.self.seatid == banker.seatid) ? true : false,
																					'isStartPk': banker.isPkResult ? false : true,
																					'pkType': data.type
																				}
																]
			);
			
			if (!banker.isPkResult) banker.isPkResult = true;
		}
		
		private function gameOver():void
		{
			Log.info("gameOver", playerListP.getSeats());
			
			expCalculation();

			var seats:Array = playerListP.getSeats();
			for (var i:* in seats)
			{
				playerListP.getPlayerInSeat(seats[i]).reset();
			}
			
			sendNotification(RoomMediator.GAME_OVER_RESPONSE, [gameConfigP.self, playerListP.getSeats().length]);
			
			gameConfigP.gameStatus = RoomConnProxy.STAT_WAIT_START;
			
			checkBanker();
			checkplayr();
			checkAnonymous();
		}
		
		private function expCalculation():void
		{
			if (gameConfigP.self.increaseExp > 0)
			{
				gameConfigP.self.exp = gameConfigP.self.exp + gameConfigP.self.increaseExp;
				var levelData:LevelData = gameConfigP.getCurrentLevelExp(gameConfigP.self.exp, analysisXmlP.levels);
				var isNewLevel:Boolean = false;
				if (levelData.sublevel != gameConfigP.self.sublevel || levelData.star != gameConfigP.self.star)
				{
					isNewLevel = true;
					
					gameConfigP.self.sublevel = levelData.sublevel;
					gameConfigP.self.star = levelData.star;
				}
				
				sendNotification(RoomMediator.EXP_ADD_RESPONSE, 
									[gameConfigP.self, gameConfigP.self.increaseExp, isNewLevel, levelData]);
									
				gameConfigP.self.increaseExp = 0;
			}
		}
		
		private function checkAnonymous():void
		{
			if (gameConfigP.self.isAnonymous)
			{
				if (gameConfigP.self.playGameTimes != 0 && gameConfigP.self.playGameTimes % 5 == 0)
					Js.call(Js.GOTO_INSTALL_APP);
				
				gameConfigP.self.playGameTimes = gameConfigP.self.playGameTimes + 1;
			}
		}
		
		private function checkBanker():void
		{
			if (gameConfigP.self.seatid == GameConfigProxy.BANKER_SEATID &&
				gameConfigP.self.sitChips < 15000)
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_20", requestGoHall]);
			}
		}
		
		private function checkplayr():void
		{
			var room:HallListItemData = roomListP.get(gameConfigP.roomid);
			if (gameConfigP.self.seatid > GameConfigProxy.BANKER_SEATID && gameConfigP.self.sitChips < room.minPour)
			{
				gameConfigP.isReExchangeChip = true;
				requestStand();
			}
			
			if (gameConfigP.self.seatid > GameConfigProxy.BANKER_SEATID && gameConfigP.self.sitChips > 15000)
			{
				sendNotification(AppFacade.CLIENT_NOTICE, ["error_21", requestGoHall]);
			}
		}
		
		private function showLastResult():void
		{
			var seatid:int = gameConfigP.self.seatid;
			if (seatid <= 0 || seatid == GameConfigProxy.BANKER_SEATID)
			{
				var seatids:Array = playerListP.getSeats();
				var len:int = seatids.length;
				for (var i:int = 0; i < len; i++)
				{
					if (seatids[i] != GameConfigProxy.BANKER_SEATID)
					{
						seatid = seatids[i];
						break;
					}
				}
			}
			sendNotification(DialogManagerMediator.SHOW_DIALOG, ['pkResultView', { 'isClick': true, 'seatid': seatid} ]);
		}
		
		private function expressionDeal(data:Object):void
		{
			data['mid'] = int(data['mid']);
			data["flag"] = int(data["flag"]);
			var user:UserData = playerListP.getUidByPlayer(data['mid']);
			if (user)
			{
				sendNotification(RoomMediator.EXPRESSION_RESPONSE, [user.seatid, user.mid, data["flag"]]);
			}
		}

		private function shotUser():void
		{
			
		}

		///////////////////////////////////////
		///// model 引用
		//////////////////////////////////////
		
		private function get hallConnP():HallConnProxy
		{
			return facade.retrieveProxy(HallConnProxy.NAME) as HallConnProxy;
		}
		
		private function get roomConnP():RoomConnProxy
		{
			return facade.retrieveProxy(RoomConnProxy.NAME) as RoomConnProxy;
		}
		
		private function get gameConfigP():GameConfigProxy
		{
			return facade.retrieveProxy(GameConfigProxy.NAME) as GameConfigProxy;
		}
		
		private function get analysisXmlP():AnalysisXMLProxy
		{
			return facade.retrieveProxy(AnalysisXMLProxy.NAME) as AnalysisXMLProxy;
		}
		
		private function get playerListP():PlayerListProxy
		{
			return facade.retrieveProxy(PlayerListProxy.NAME) as PlayerListProxy;
		}
		
		private function get roomListP():RoomListProxy
		{
			return facade.retrieveProxy(RoomListProxy.NAME) as RoomListProxy;
		}
	}

}